package com.example.aboutspringboot.mapper;

import com.example.aboutspringboot.entity.Order;
import com.example.aboutspringboot.entity.OrderItem;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface OrderMapper {

    //查询所有订单
    @Select("select id,date,username from orderitem")
    List<Order> selectOrderAll();

    //查订单
    @Select("select id,name,price,number from orderitems where id=#{id}")
    List<OrderItem> selectOrderItem(long id);

    //按名和日期查订单id
    @Select("select id from orderitem where username=#{username} and date=#{date}")
    int selectOrderItemId(String username,String date);

    //创建订单
    @Insert("insert into orderitem(username,date)values(#{username},#{date})")
    int insertOrder(Order order);

    @Insert("insert into orderitems(id,name,price,number)values(#{id},#{name},#{price},#{number})")
    int insertOrderItem(OrderItem orderItem);
}
